package com.smartwebx.ha.dal.realtime.dao;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.smartwebx.ha.dal.config.OracleConfigInfo;
import com.smartwebx.ha.dal.inter.water.IQProcessDataOperatDao;
import com.smartwebx.ha.dal.inter.water.IZProcessDataOperatDao;
import com.smartwebx.ha.dal.realtime.sqlprovider.RiverProvider;
import com.smartwebx.ha.dal.usebean.DateValue;
import com.smartwebx.ha.dal.usebean.RiverFlood;
import com.smartwebx.ha.dal.usebean.enu.FlowTypeEnum;

/**
 * 河道
 * 
 * @author zhangxi
 * 
 */
public interface RiverMapper extends IZProcessDataOperatDao,
		IQProcessDataOperatDao {
	String ST_RIVER_R = OracleConfigInfo.REALTIME_NAME + ".ST_RIVER_R";

	/**
	 * 单站小时水位过程数据
	 * 
	 * @param stcd
	 * @param startHour
	 * @param endHour
	 * @return
	 */
	@Select("SELECT TM,Z val FROM " + ST_RIVER_R
			+ " WHERE STCD=#{stcd} AND TM>=#{startHour} AND TM<#{endHour}")
	public List<DateValue> getSingleStatHourZProcess(
			@Param("stcd") String stcd, @Param("startHour") Date startHour,
			@Param("endHour") Date endHour);

	/**
	 * 返回查询时间点的上一条水位数据
	 * 
	 * @param stcd
	 * @param startHour
	 * @return
	 */
	@Select("SELECT TM,Z val FROM "
			+ ST_RIVER_R
			+ " WHERE STCD=#{stcd} AND TM<#{datePoint} AND ROWNUM=1 ORDER BY TM DESC")
	public DateValue getStartHourBeforeZVal(@Param("stcd") String stcd,
			@Param("datePoint") Date tmPoint);

	/**
	 * 获得单站日水位过程（取每日8时数据）
	 * 
	 * @param stcd
	 * @param startHour
	 * @param endHour
	 * @return
	 */
	@Select("SELECT TM,Z val FROM "
			+ ST_RIVER_R
			+ " WHERE STCD=#{stcd} AND TM>=#{startDate} AND TM<#{endDate} AND to_char(TM,'HH24')=8")
	public List<DateValue> getSingleStatDayZProcess(@Param("stcd") String stcd,
			@Param("startDate") Date startDate, @Param("endDate") Date endDate);

	/**
	 * 单站小时流量过程数据
	 * 
	 * @param stcd
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@Select("SELECT TM,Q val FROM " + ST_RIVER_R
			+ " WHERE STCD=#{stcd} AND TM>=#{startHour} AND TM<#{endHour}")
	public List<DateValue> getSingleStatHourQProcess(
			@Param("stcd") String stcd, @Param("startHour") Date startDate,
			@Param("endHour") Date endDate);

	/**
	 * 返回查询时间点的上一条流量数据
	 * 
	 * @param stcd
	 * @param tmPoint
	 * @return
	 */
	@Select("SELECT TM,Q val FROM "
			+ ST_RIVER_R
			+ " WHERE STCD=#{stcd} AND TM>=#{datePoint}-5 AND TM<#{datePoint} AND ROWNUM=1 ORDER BY TM DESC")
	public DateValue getStartHourBeforeQVal(@Param("stcd") String stcd,
			@Param("datePoint") Date datePoint);

	/**
	 * 获得单站日流量过程（取每日8时数据）
	 * 
	 * @param stcd
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@Select("SELECT TM,Q val FROM "
			+ ST_RIVER_R
			+ " WHERE STCD=#{stcd} AND TM>=#{startDate} AND TM<#{endDate} AND to_char(TM,'HH24')=8")
	public List<DateValue> getSingleStatDayQProcess(@Param("stcd") String stcd,
			@Param("startDate") Date startDate, @Param("endDate") Date endDate);

	/**
	 * 根据 tabType 得到日平均流量或者日流量数据
	 * 
	 * @param stcd
	 * @param startDate
	 *            日期（不包括时间）
	 * @param endDate
	 *            日期（不包括时间）
	 * @param tabType
	 *            avg (日平均流量) / day (日流量)
	 * @return
	 */
	@SelectProvider(type = RiverProvider.class, method = "getDayFlowerProcessSQL")
	public List<DateValue> getDayFlowerProcess(@Param("stcd") String stcd,
			@Param("startDate") Date startDate, @Param("endDate") Date endDate,
			@Param("tabType") FlowTypeEnum tabType);

	/**
	 * 获得河道防洪指标
	 * 
	 * @param stcd
	 * @return
	 */
	@Select("SELECT * FROM " + OracleConfigInfo.REALTIME_NAME
			+ ".ST_RVFCCH_B WHERE STCD=#{stcd}")
	public RiverFlood getRiverFlood(@Param("stcd") String stcd);

}